import React, { Component } from 'react'

export default class App extends Component {
    constructor(porps){
        super(porps);
        this.state={
            num:10
        }
    }
    add(){
        this.setState({
            num:this.state.num+1
        },()=>{
            console.log("修改后的num为"+this.state.num)
        })
        console.log(this.state.num)
    }
    subtraction(){
        setTimeout(()=>{
            this.setState({
                num:this.state.num-1
            },()=>{
                console.log("修改后的num为"+this.state.num)
            })
            console.log("我现在是同步的");
        },200)
    }
    adds(n){
        this.setState({
            num:this.state.num+n
        })
    }
    addx=()=>{
        this.setState({
            num:this.state.num+5
        })
    }
  render() {
    return (
        <>
      <div>数字：{this.state.num}</div>
      <div><button onClick={()=>{
          this.add();
      }}>+</button></div>
    
      <div><button onClick={()=>{
          this.subtraction();
      }}>-</button></div>
      <div><button onClick={this.adds.bind(this,10)}>+10</button></div>

      <div><button onClick={this.addx}>+5</button></div>
      
      </>
    )
  }
}
